package com.kyxx.topics.utils;

import java.math.BigDecimal;

public class BigDecimalUtils {
	private static final int DEF_DIV_SCALE = 10;

	public static double add(double paramDouble1, double paramDouble2) {
		return new BigDecimal(Double.toString(paramDouble1)).add(
				new BigDecimal(Double.toString(paramDouble2))).doubleValue();
	}

	public static int compareTo(double paramDouble1, double paramDouble2) {
		return new BigDecimal(paramDouble1).compareTo(new BigDecimal(
				paramDouble2));
	}

	public static float convertsToFloat(double paramDouble) {
		return new BigDecimal(paramDouble).floatValue();
	}

	public static int convertsToInt(double paramDouble) {
		return new BigDecimal(paramDouble).intValue();
	}

	public static long convertsToLong(double paramDouble) {
		return new BigDecimal(paramDouble).longValue();
	}

	public static double div(double paramDouble1, double paramDouble2) {
		return div(paramDouble1, paramDouble2, 10);
	}

	public static double div(double paramDouble1, double paramDouble2,
			int paramInt) {
		if (paramInt < 0)
			throw new IllegalArgumentException(
					"The scale must be a positive integer or zero");
		return new BigDecimal(Double.toString(paramDouble1)).divide(
				new BigDecimal(Double.toString(paramDouble2)), paramInt, 4)
				.doubleValue();
	}

	public static double mul(double paramDouble1, double paramDouble2) {
		return new BigDecimal(Double.toString(paramDouble1)).multiply(
				new BigDecimal(Double.toString(paramDouble2))).doubleValue();
	}

	public static double returnMax(double paramDouble1, double paramDouble2) {
		return new BigDecimal(paramDouble1).max(new BigDecimal(paramDouble2))
				.doubleValue();
	}

	public static double returnMin(double paramDouble1, double paramDouble2) {
		return new BigDecimal(paramDouble1).min(new BigDecimal(paramDouble2))
				.doubleValue();
	}

	public static double round(double paramDouble, int paramInt) {
		if (paramInt < 0)
			throw new IllegalArgumentException(
					"The scale must be a positive integer or zero");
		return new BigDecimal(Double.toString(paramDouble)).divide(
				new BigDecimal("1"), paramInt, 4).doubleValue();
	}

	public static double sub(double paramDouble1, double paramDouble2) {
		return new BigDecimal(Double.toString(paramDouble1)).subtract(
				new BigDecimal(Double.toString(paramDouble2))).doubleValue();
	}
}